package com.ruoyi.project.channel.channelAccountSub.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.channelAccountSub.domain.ChannelAccountSub;
import com.ruoyi.project.channel.channelAccountSub.service.IChannelAccountSubService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 子账号信息操作处理
 *
 * @author CAIN
 * @date 2019-09-26
 */
@Controller
@RequestMapping("/channel/channelAccountSub")
public class ChannelAccountSubController extends BaseController {
    private String prefix = "channel/channelAccountSub";

    @Autowired
    private IChannelAccountSubService channelAccountSubService;

    @RequiresPermissions("channel:channelAccountSub:view")
    @GetMapping("/{accountId}")
    public String channelAccountSub(@PathVariable("accountId") String accountId, ModelMap mmap) {
		mmap.put("accountId", accountId);
    	return prefix + "/channelAccountSub";
    }

    /**
     * 查询子账号列表
     */
    @RequiresPermissions("channel:channelAccountSub:list")
    @PostMapping("/list/{accountId}")
    @ResponseBody
    public TableDataInfo list(@PathVariable("accountId") String accountId, ChannelAccountSub channelAccountSub) {
        startPage();
        channelAccountSub.setAccountId(accountId);
        List<ChannelAccountSub> list = channelAccountSubService.selectChannelAccountSubList(channelAccountSub);
        return getDataTable(list);
    }


    /**
     * 导出子账号列表
     */
    @RequiresPermissions("channel:channelAccountSub:export")
    @PostMapping("/export/{accountId}")
    @ResponseBody
    public AjaxResult export(@PathVariable("accountId") String accountId, ChannelAccountSub channelAccountSub) {
        channelAccountSub.setAccountId(accountId);
        List<ChannelAccountSub> list = channelAccountSubService.selectChannelAccountSubList(channelAccountSub);
        ExcelUtil<ChannelAccountSub> util = new ExcelUtil<ChannelAccountSub>(ChannelAccountSub.class);
        return util.exportExcel(list, "channelAccountSub");
    }

    /**
     * 新增子账号
     */
    @GetMapping("/add/{accountId}")
    public String add(@PathVariable("accountId") String accountId, ModelMap mmap) {
		mmap.put("accountId", accountId);
    	return prefix + "/add";
    }

    /**
     * 新增保存子账号
     */
    @RequiresPermissions("channel:channelAccountSub:add")
    @Log(title = "子账号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChannelAccountSub channelAccountSub) {
        return toAjax(channelAccountSubService.insertChannelAccountSub(channelAccountSub));
    }

    /**
     * 修改子账号
     */
    @GetMapping("/edit/{subAccountId}")
    public String edit(@PathVariable("subAccountId") Long subAccountId, ModelMap mmap) {
        ChannelAccountSub channelAccountSub = channelAccountSubService.selectChannelAccountSubById(subAccountId);
        mmap.put("channelAccountSub", channelAccountSub);
        return prefix + "/edit";
    }

    /**
     * 修改保存子账号
     */
    @RequiresPermissions("channel:channelAccountSub:edit")
    @Log(title = "子账号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChannelAccountSub channelAccountSub) {
        return toAjax(channelAccountSubService.updateChannelAccountSub(channelAccountSub));
    }

    /**
     * 删除子账号
     */
    @RequiresPermissions("channel:channelAccountSub:remove")
    @Log(title = "子账号", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(channelAccountSubService.deleteChannelAccountSubByIds(ids));
    }

}
